/*
 * @Description: 描述信息
 * @Version: 版本号
 * @Author: xuebao
 * @Date: 2023-12-14 18:28:10
 * @LastEditors: xuebao
 * @LastEditTime: 2023-12-15 13:15:03
 */
import { IAuthLoader } from '@/router/AuthLoader'
import { Breadcrumb } from 'antd'
import { ReactNode, useEffect, useState } from 'react'
import { useLocation, useRouteLoaderData } from 'react-router-dom'
import { findTreeNode } from '@/utils'
export default function BreadCrumb() {
  const [breadList, setBreadList] = useState<(string | ReactNode)[]>([])
  //权限
  const data = useRouteLoaderData('layout') as IAuthLoader
  const { pathname } = useLocation()
  useEffect(() => {
    const list = findTreeNode(data.menuList, pathname, [])
    setBreadList([<a href='/welcome'></a>, ...list])
  }, [pathname])
  return (
    <div>
      <Breadcrumb items={breadList.map((item) => ({ title: item }))} style={{ marginLeft: 10 }}></Breadcrumb>
    </div>
  )
}
